﻿using LuShanTea.Service.Entities;
using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LuShanTea.Service.ModelConfig
{
    public class GoodConfig : EntityTypeConfiguration<Good>
    {
        public GoodConfig()
        {
            this.ToTable("T_Goods");
            this.Property(e => e.Name).IsRequired().HasMaxLength(128);
            this.Property(e => e.Describe).IsRequired().HasMaxLength(256);
            this.HasRequired(e => e.Category).WithMany().HasForeignKey(e => e.CateGoriesId).WillCascadeOnDelete(false);
            this.HasRequired(e => e.City).WithMany().HasForeignKey(e => e.CityId).WillCascadeOnDelete(false);

            this.HasMany(e => e.Packs).WithMany(e => e.Goods).Map(e => e.ToTable("T_GoodPacks").MapLeftKey("GoodId").MapRightKey("PackId"));
        }

    }
}
